﻿using System;

namespace Xenta.Events
{
    /// <summary>
    /// Exposes the event broker interface.
    /// </summary>
    /// <remarks>
    /// The event broker component is a core part of 
    /// the eventing system. This component allows to 
    /// subscribe/unsubscribe a handler to an event. When 
    /// event is  published, the broker dispatches it 
    /// to all related subscribers(handlers).
    /// Important! There can be only one event broker in 
    /// the system and the event broker should be a 
    /// singleton instance.
    /// </remarks>
    public interface IEventBroker : IDependency, IDisposable
    {
        #region Methods

        /// <summary>
        /// Dispatches the event.
        /// </summary>
        /// <typeparam name="TEvent">The type of event.</typeparam>
        /// <param name="evt">The event object.</param>
        void Publish<TEvent>(TEvent evt) 
            where TEvent : IEvent;

        /// <summary>
        /// Registers the event handler.
        /// </summary>
        /// <typeparam name="TEvent">The type of event.</typeparam>
        /// <param name="handler">The event handler.</param>
        /// <param name="marker">An optional event marker.</param>
        void Subscribe<TEvent>(Action<TEvent> handler, object marker = null) 
            where TEvent : IEvent;

        /// <summary>
        /// Removes the event handler.
        /// </summary>
        /// <typeparam name="TEvent">The type of event.</typeparam>
        /// <param name="handler">The event handler.</param>
        /// <param name="marker">An optional event marker.</param>
        void Unsubscribe<TEvent>(Action<TEvent> handler, object marker = null) 
            where TEvent : IEvent;

        #endregion
    }
}
